/* Hello World Example

   This example code is in the Public Domain (or CC0 licensed, at your option.)

   Unless required by applicable law or agreed to in writing, this
   software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
   CONDITIONS OF ANY KIND, either express or implied.
*/
#include <stdio.h>
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_spi_flash.h"

#include "app_common.h"
// app文头文件包含
#include "app_rtc.h"
#include "app_rgb.h"
#include "app_gui.h"
#include "app_button.h"
#include "app_sntp.h"
#include "app_wifi.h"
#include "app_weather.h"
#if (TTS_ENABLE == STD_ON)
#include "app_tts_voice.h"
#endif /* (TTS_ENABLE == STD_ON) */
#include "app_lamp_mngr.h"
#include "app_aliyun.h"
#include "app_uart.h"


#define PRINTF_CHIP_INTO              (STD_OFF)


void app_main(void)
{
    printf("Smart Desk Lamp Startup!\n");

#if (PRINTF_CHIP_INTO == STD_ON)
    /* Print chip information */
    esp_chip_info_t chip_info;
    esp_chip_info(&chip_info);
    printf("This is %s chip with %d CPU core(s), WiFi%s%s, ",
            CONFIG_IDF_TARGET,
            chip_info.cores,
            (chip_info.features & CHIP_FEATURE_BT) ? "/BT" : "",
            (chip_info.features & CHIP_FEATURE_BLE) ? "/BLE" : "");

    printf("silicon revision %d, ", chip_info.revision);

    printf("%dMB %s flash\n", spi_flash_get_chip_size() / (1024 * 1024),
            (chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" : "external");

    printf("Minimum free heap size: %d bytes\n", esp_get_minimum_free_heap_size());
#endif

    // 初始化本地默认时间
    Rtc_TimeInit();
    /* 初始化台灯控制任务 LEDC */
    Lamp_LedcInit();
    // 初始化SNTP任务
    Sntp_Init();
	// 初始化RGB端口
    Rgb_Init();
    // 初始化ADC按键
//    Btn_AdcInit();
    Btn_TaskInit();
    // 初始化GUI(lvgl)
    Gui_TaskInit();
    // 初始化串口
    Uart_TaskInit();
#if (WEATHER_DEBUG == STD_ON)
    // 初始化天气任务
    Weather_TaskInit();
#endif
#if (WIFI_METHOD_ALIYUN == STD_OFF)
    // 初始化wifi
    Wifi_AppInit();
#else
    // 阿里云初始化
    Aliyun_Init();
#endif
#if (TTS_ENABLE == STD_ON)
    Audio_PlayerChinese("您好，欢迎使用智能网络台灯");
#endif /* (TTS_ENABLE == STD_ON) */

    while (1)
    {
		// RGB控制程序
		Rgb_Control();

		// Lamp台灯控制程序
		Lamp_Mngr();

    	vTaskDelay(pdMS_TO_TICKS(200));
    }
}


